﻿SET QUOTED_IDENTIFIER ON
GO
SET ARITHABORT ON
GO
SET NUMERIC_ROUNDABORT OFF
GO
SET CONCAT_NULL_YIELDS_NULL ON
GO
SET ANSI_NULLS ON
GO
SET ANSI_PADDING ON
GO
SET ANSI_WARNINGS ON
GO

ALTER TABLE dbo.bht_Groups ADD
	EnableTranslate bit NULL
GO
ALTER TABLE dbo.bht_Groups ADD CONSTRAINT
	DF_bht_Groups_EnableTranslate DEFAULT 1 FOR EnableTranslate
GO
UPDATE
	bht_Groups
SET
	EnableTranslate = 1
GO

ALTER PROCEDURE [dbo].[bhp_NemoGroupGetAll]
AS
BEGIN

	SELECT 
		t.id as Id,
		g.name as Name,
		t.name as SystemName,
		g.Identyficator,
		t.name as SelectTable,
		CASE t.typ WHEN 'T' THEN 'Table' WHEN 'V' THEN 'View' WHEN 'TE' THEN 'ExtendedTable' ELSE '' END as [Type],
		ISNULL(g.EnableTranslate, 1) AS EnableTranslate
	FROM 
		sTree t
		LEFT JOIN bht_Groups g ON t.id = g.Id
	WHERE
		(del IS NULL OR del = 0)
		AND typ IN ('V', 'T')
		AND parent = 0

END
GO

ALTER PROCEDURE [dbo].[bhp_NemoGroupGet]
	@Id				INT
AS
BEGIN

	SELECT 
		t.id as Id,
		g.name as Name,
		t.name as SystemName,
		g.Identyficator,
		t.name as SelectTable,
		CASE t.typ WHEN 'T' THEN 'Table' WHEN 'V' THEN 'View' WHEN 'TE' THEN 'ExtendedTable' ELSE '' END as [Type],
		ISNULL(g.EnableTranslate, 1) AS EnableTranslate
	FROM 
		sTree t
		LEFT JOIN bht_Groups g ON t.id = g.Id
	WHERE
		(del IS NULL OR del = 0)
		AND typ IN ('V', 'T')
		AND parent = 0
		AND t.id = @Id

END

GO
